package com.itjin.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itjin.model.domain.entity.Course;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 课程信息Mapper
 */
@Mapper
public interface CourseMapper extends BaseMapper<Course> {

    /**
     * 查询用户在指定时间段和周次范围内的课程（用于冲突检查）
     * @param userId 用户ID
     * @param classTime 课程时间段
     * @param weekStart 开始周次
     * @param weekEnd 结束周次
     * @param excludeCourseId 排除的课程ID（编辑时使用）
     * @return 可能冲突的课程列表
     */
    @Select({
        "<script>",
        "SELECT * FROM course WHERE userId = #{userId} AND isDelete = 0",
        "AND classTime IS NOT NULL AND classTime != ''",
        "AND NOT (weekEnd &lt; #{weekStart} OR weekStart &gt; #{weekEnd})",
        "<if test='excludeCourseId != null'>",
        "AND id != #{excludeCourseId}",
        "</if>",
        "</script>"
    })
    List<Course> findConflictCourses(@Param("userId") Integer userId,
                                   @Param("classTime") String classTime,
                                   @Param("weekStart") Integer weekStart,
                                   @Param("weekEnd") Integer weekEnd,
                                   @Param("excludeCourseId") Integer excludeCourseId);
} 